
/**
 * 创建多进程
*/

#include <stdio.h>
#include <unistd.h>

int main()
{

    printf("Current progress id %d\n", getpid());

    pid_t pid = fork();
    if (0 == pid)
    { // 子进程
        printf("I am child process pid is %d,"
        " ppid is %d, fork return is %d\n",
               getpid(), getppid(), pid);
    }
    else if (0 < pid)
    { // 父进程
        printf("I am parent process pid is %d," 
        "ppid is %d, fork return is %d\n",
               getpid(), getppid(), pid);
    }
    else
    { // 错误
        perror("fork error : ");
    }

    sleep(1);
    printf("progress id %d\n", getpid());
    return 0;
}